<template>
  <div>
    <!-- 头部 -->
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/index' }"
          >首页</el-breadcrumb-item
        >
        <el-breadcrumb-item>酬金政策维护</el-breadcrumb-item>
      </el-breadcrumb>

    <!-- 条件查询 -->
    <el-card class="boxCard">
      <div>
          <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item>条件区域</el-breadcrumb-item>
        </el-breadcrumb>


        <!-- 政策名称 -->
        <el-row>
          <el-col :span="2" class="right">
              政策名称：
          </el-col>
          <el-col :span="10" class="left">
              <el-input placeholder="请输入内容" v-model="searchPN" clearable>
              </el-input>
          </el-col>

          <!-- 状态 -->
          <el-col :span="2" class="right">
            状态：
          </el-col>
          <el-col :span="10" class="left">
                        <template>
              <el-select v-model="value" placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </template>
          </el-col>
        </el-row>

        <!-- 生效时间 -->
        <el-row>
          <el-col :span="2" class="right">
              生效时间：
          </el-col>
          <el-col :span="10" class="left">
                <el-date-picker
                  v-model="EFT1"
                  type="date"
                  placeholder="选择日期"
                >
                </el-date-picker
                > ~
                <el-date-picker
                  v-model="EFT2"
                  type="date"
                  placeholder="选择日期"
                >
               </el-date-picker>
          </el-col>

          <!-- 失效时间 -->

          <el-col :span="2" class="right">
            失效时间：
          </el-col>
          <el-col :span="10" class="left">
                <el-date-picker
                  v-model="EXT1"
                  type="date"
                  placeholder="选择日期"
                >
                </el-date-picker
                > ~
                <el-date-picker
                  v-model="EXT2"
                  type="date"
                  placeholder="选择日期"
                >
                </el-date-picker>
          </el-col>

        </el-row>

        <!-- 单选框 -->
        <el-row>

          <el-col :span="2" class="right">
              酬金科目：
          </el-col>
          <el-col :span="10" class="left">
              <label style="margin-right:15px; font-size:14px;" v-for="(item, index) in radioData" :key="index">
                <input
                  type="radio"
                  v-model="radioVal"
                  :value="item.value"
                  @change="getRadioVal"
                />
                {{ item.value }}
              </label>
          </el-col>
        </el-row>

        <!-- 政策公文名称 -->
        <el-row>
          <el-col :span="2" class="right">
              关联公文名：
          </el-col>
          <el-col :span="10" class="left">
              <el-input placeholder="请输入内容" v-model="searchDN" clearable>
              </el-input>
          </el-col>
        </el-row>
      </div>
    </el-card>
    <el-card class="boxCard">
            <div class="grid-content bg-purple-dark">
              <el-button type="primary" @click="searchAll">查询</el-button>
              <el-button type="warning" @click="resetAll">重置</el-button>

            </div>
    </el-card>




    <!-- 表格 -->
    <div class="part2">

      <!-- 表格内容 -->

      <el-card>
      <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item>列表区域</el-breadcrumb-item>
      </el-breadcrumb>
        <el-table :data="tableData" height="350" border style="width: 100%">
          <el-table-column prop="policyName" label="酬金政策名称" align="center">

          </el-table-column>
          <el-table-column prop="courseName" label="酬金科目" align="center">
          </el-table-column>
          <el-table-column prop="documentName" label="关联公文" align="center">
          </el-table-column>
          <el-table-column prop="effectiveTime" label="生效时间" align="center">
          </el-table-column>
          <el-table-column prop="expirationTime" label="失效时间" align="center">
          </el-table-column>
          <el-table-column prop="policyAction" label="状态" align="center">
            <template slot-scope="scope">
              <span
                :class="
                  scope.row.policyAction == 1
                    ? 'pass-audit'
                    : scope.row.policyAction == 2
                    ? 'wait-audit'
                    : 'faile-audit'
                "
                >{{
                  scope.row.policyAction == 1
                    ? "审核通过"
                    : scope.row.policyAction == 2
                    ? "待审核"
                    : "审核未通过"
                }}</span
              >
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center">
            <!-- 查看按钮 -->
            <template slot-scope="scope">
              <el-button :class="scope.row.policyAction==0?'hide':'show'"
                icon="el-icon-search"
                circle
                size="small"
                @click="checkPolicy(scope.row)"
              >
              </el-button>
              <!-- 修改按钮 -->
              <el-button
                :class="scope.row.policyAction==2?'hide':'show'"
                type="primary"
                icon="el-icon-edit"
                circle
                size="small"
                @click="editPolicy(scope.row)"
              ></el-button>
              <!-- 删除按钮 -->
              <el-button
                :class="scope.row.policyAction==2?'hide':scope.row.policyAction==0?'hide':'show'"
                type="danger"
                icon="el-icon-delete"
                size="small"
                circle
                @click="delPolicy(scope.row.id)"
              ></el-button>
            </template>
          </el-table-column>
        </el-table>
      <!-- 页脚内容 -->
        <div class="page">
                          <el-pagination
                        background
                        layout="prev, pager, next" :total="this.count"
                        @current-change="fengye($event)"
                >
                </el-pagination>
                总条数:{{ this.count }}
                当前页数: {{ this.page }}/{{ this.pageCount }} 页
      </div>
      </el-card>

      <!-- 修改对话框 -->
      <el-dialog title="修改信息" :visible.sync="dialogFormEditVisible">
        <el-form :model="editform">
          <el-form-item label="酬金政策名称：">
            <el-input
              v-model="editform.policyName"
              autocomplete="off"
            ></el-input>
          </el-form-item>

          <el-form-item label="酬金科目：">
            <el-input
              v-model="editform.courseName"
              autocomplete="off"
            ></el-input>
          </el-form-item>

          <el-form-item label="关联公文：">
            <el-input
              v-model="editform.documentName"
              autocomplete="off"
            ></el-input>
          </el-form-item>

          <el-form-item label="生效时间：">
            <el-input
              v-model="editform.effectiveTime"
              autocomplete="off"
            ></el-input
            >~
            <el-input
              v-model="editform.effectiveTime2"
              autocomplete="off"
            ></el-input>
          </el-form-item>

          <el-form-item label="失效时间：">
            <el-input
              v-model="editform.expirationTime"
              autocomplete="off"
            ></el-input
            >~
            <el-input
              v-model="editform.expirationTime2"
              autocomplete="off"
            ></el-input>
          </el-form-item>

          <el-button type="primary" @click="resetTheAudit" :class="this.checkform.policyAction==2?'hide':this.checkform.policyAction==0?'show':'hide'">
            重新审核
          </el-button>

          <!-- <el-form-item label="状态" class="selStatus">
            <br />
            <el-select
              v-model="editform.policyAction"
              select="editform.policyAction"
              autocomplete="off"
            >
              <el-option label="待审核" :value="2"> </el-option>
              <el-option label="审核通过" :value="1"> </el-option>
              <el-option label="审核未通过" :value="0"> </el-option>
            </el-select>
          </el-form-item> -->
        </el-form>


        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormEditVisible = false">取消</el-button>
          <el-button type="primary" @click="savePolicy">保存</el-button>
        </div>
      </el-dialog>

      <!-- 查看对话框 -->

      <el-dialog title="查看信息" :visible.sync="dialogFormCheckVisible" width="400px">
        <el-form :model="checkform">
          <el-form-item label="酬金政策名称：">
            {{ this.checkform.policyName }}
          </el-form-item>

          <el-form-item label="酬金科目：">
            {{ this.checkform.courseName }}
          </el-form-item>

          <el-form-item label="关联公文：">
            {{ this.checkform.documentName }}
          </el-form-item>

          <el-form-item label="生效时间：">
            {{ this.checkform.effectiveTime }}
            {{ this.checkform.effectiveTime2 }}
          </el-form-item>

          <el-form-item label="失效时间：">
            {{ this.checkform.expirationTime }}
            {{ this.checkform.expirationTime2 }}
          </el-form-item>

          <el-form-item label="状态：" class="selStatus">
            {{
              this.checkform.policyAction == 0
                ? "审核未通过"
                : this.checkform.policyAction == 2
                ? "待审核"
                : "审核通过"
            }}
          </el-form-item>
            
              <el-button type="primary" @click="passTheAudit" :class="this.checkform.policyAction==1?'hide':'show'">
                审核通过
              </el-button>


        </el-form>

        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormCheckVisible = false">关闭</el-button>
        </div>
      </el-dialog>


 
    </div>
  </div>
</template>

<script>
export default {
  name: "Maintain",
  data() {
    return {
      tableData: [],
      searchData: [],
      limit: 10,
      page: 1,
      pageCount: 0,
      count: 0,
      EFT1: "",
      EFT2: "",
      EXT1: "",
      EXT2: "",
      searchPN: "",
      value: '',
      radioVal: "",
      searchDN: "",
      dialogFormEditVisible: false,
      dialogFormCheckVisible: false,
      editform: {
        id: "",
        policyName: "",
        courseName: "",
        documentName: "",
        effectiveTime1: "",
        effectiveTime2: "",
        expirationTime1: "",
        expirationTime2: "",
        policyAction: "0",
        examinationReport:"string"        
      },
      checkform: {
        id: "",
        policyName: "",
        courseName: "",
        documentName: "",
        effectiveTime1: "",
        effectiveTime2: "",
        expirationTime1: "",
        expirationTime2: "",
        policyAction: "0",
        examinationReport:"string"
      },
      radioData: [
        { value: "放号类" },
        { value: "终端类" },
        { value: "数据业务类" },
        { value: "业务类" },
        { value: "激励类" },
        { value: "考核类" },
      ],
      options: [
        {
          value: "",
          label: "全部",
        },
        {
          value: 2,
          label: "待审核",
        },
        {
          value: 1,
          label: "审核通过",
        },
        {
          value: 0,
          label: "审核未通过",
        },
      ],
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
      },
    };
  },
  mounted: function () {
    this.displayPolicy();
  },

  methods: {
    getRadioVal() {
      console.log(this.radioVal);
    },
    displayPolicy: function () {
      this.limit=10,
      this.page=1,
      this.pageCount=0,
      this.count=0,
      this.$axios
        .post("api/policyInfo/selectInfoForPage", { limit: 10, page: 1 })
        .then((response) => {
          let result = response.data;
          console.log(result);
          if (result.code == 200) {
            this.tableData = result.data;
            this.pageCount = result.pageCount;
            this.count = result.count;
          } else {
            this.$alert(result.message);
          }
        })
        .catch(() => {});
    },
    fengye: function (e) {
      console.log(e);
      this.page = e;
      this.$axios
        .post("api/policyInfo/selectInfoForPage", { limit: 10, page: e })
        .then((response) => {
          let result = response.data;
          console.log(result);
          if (result.code == 200) {
            this.tableData = [];
            this.tableData = result.data;
            console.log(tableData);
          } else {
            this.$alert(result.message);
          }
        })
        .catch(() => {});
    },
    editPolicy: function (obj) {
      this.dialogFormEditVisible = true;
      this.editform.id = obj.id;
      this.editform.policyName = obj.policyName;
      this.editform.courseName = obj.courseName;
      this.editform.documentName = obj.documentName;
      this.editform.effectiveTime = obj.effectiveTime;
      this.editform.effectiveTime2 = obj.effectiveTime2;
      this.editform.expirationTime = obj.expirationTime;
      this.editform.expirationTime2 = obj.expirationTime2;
      this.editform.policyAction = obj.policyAction;
      this.checkform.examinationReport="string"      
    },
    savePolicy: function (obj) {
      console.log(this.editform);
      this.$axios
        .post("api/policyInfo/updateById", {
          id: this.editform.id,
          policyName: this.editform.policyName,
          courseName: this.editform.courseName,
          documentName: this.editform.documentName,
          effectiveTime: this.editform.effectiveTime,
          effectiveTime2: this.editform.effectiveTime2,
          expirationTime: this.editform.expirationTime,
          expirationTime2: this.editform.expirationTime2,
          policyAction: this.editform.policyAction,
        })
        .then((response) => {
          let result = response.data;
          console.log(result);
          if (result.code === 200) {
            this.$alert(result.msg);
            this.displayPolicy();
            this.dialogFormEditVisible = false;
          } else {
            this.$alert(result.msg);
          }
        })
        .catch(() => {
          this.$alert("请求出错");
        });
    },
    delPolicy: function (id) {
      this.$axios
        .post("api/policyInfo/deleteById", { id: id })
        .then((response) => {
          let result = response.data;
          console.log(result);
          if (result.code === 200) {
            this.displayPolicy();
          } else {
            this.$alert(result.msg);
          }
        })
        .catch((err) => {
          console.log(err);
          this.$alert("请求出错，请检查！");
        });
    },
    checkPolicy: function (obj) {
      console.log(obj)
      this.dialogFormCheckVisible = true;
      this.checkform.id = obj.id;
      this.checkform.policyName = obj.policyName;
      this.checkform.courseName = obj.courseName;
      this.checkform.documentName = obj.documentName;
      this.checkform.effectiveTime = obj.effectiveTime;
      this.checkform.effectiveTime2 = obj.effectiveTime2;
      this.checkform.expirationTime = obj.expirationTime;
      this.checkform.expirationTime2 = obj.expirationTime2;
      this.checkform.policyAction = obj.policyAction;
      this.checkform.examinationReport="string"
    },
    resetAll:function(){
      this.searchPN='',
      this.value='',
      this.EFT1='',
      this.EFT2='',
      this.EXT1='',
      this.EXT2='',
      this.radioVal='',
      this.searchDN=''
      this.displayPolicy()
    },
    getDateTimeStamp(dateStr){
      return Date.parse(dateStr.replace(/-/gi,'/'))
    },
    searchAll: function () {
      this.$axios
        .post("api/policyInfo/selectInfoForPage", {
          limit: 10,
          page: 1,
          policyAction: this.value,
          policyName: this.searchPN,
          courseName: this.radioVal,
          documentName: this.searchDN,
          effectiveTime:this.EFT1,
          effectiveTime2:this.EFT2,
          expirationTime:this.EXT1,
          expirationTime2:this.EXT2
        })
        .then((response) => {
          // console.log(this.EFT1);
          // console.log(this.EFT2)
          let result = response.data;
          console.log(result);
          if (result.code == 200) {
            this.tableData = result.data;
            this.pageCount = result.pageCount;
            this.count = result.count;
          } else {
            this.$alert(result.message);
          }
        })
        .catch(() => {});
    },
    passTheAudit:function(){
      this.$axios
        .post("api/policyInfo/examineById", {
          id: this.checkform.id,
          policyAction: 1,
          examinationReport:"string"
        })
        .then((response) => {
          let result = response.data;
          console.log(result);
          if (result.code === 200) {
            this.$alert(result.msg);
            this.displayPolicy()
            this.dialogFormCheckVisible = false;
          } else {
            this.$alert(result.msg);
          }
        })
        .catch(() => {
          this.$alert("请求出错");
        });      
    },
    resetTheAudit:function(){
      this.$axios
        .post("api/policyInfo/examineById", {
          id: this.editform.id,
          policyAction: 2,
          examinationReport:"string"
        })
        .then((response) => {
          let result = response.data;
          console.log(result);
          if (result.code === 200) {
            this.$alert(result.msg);
            this.displayPolicy()
            this.dialogFormEditVisible = false;
          } else {
            this.$alert(result.msg);
          }
        })
        .catch(() => {
          this.$alert("请求出错");
        });       
    }
  }
}
</script>

<style scoped>
.shengXiao,
.shiXiao {
  border: 1px solid #dcdfe6;
}
.right {
  text-align: right;
}
.left {
  text-align: left;
}
.boxCard {
  margin-bottom: 10px;
}
.el-input {
  width: 217px;
}

.el-row {
  text-align: left;
  margin-bottom: 10px;
}
.el-breadcrumb {
  margin-bottom: 10px;
}
.pass-audit {
  color: white;
  background-color: green;
}

.wait-audit {
  color: white;
  background-color: cadetblue;
}
.btn {
  text-align: center;
}
.faile-audit {
  color: white;
  background-color: red;
}

.show{
  display: inline-block;
}
  .page{
      margin-top: 20px;
  }
.hide{
  display: none;
}
    .el-col {
        /* border: 1px solid black; */
        height: 50px;
        line-height: 50px;
    }
.el-form{
  text-align: left !important;
}


</style>